package org.ymjava.medical.wx.web;


import org.omg.CORBA.OBJ_ADAPTER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.ymjava.medical.core.util.ResponseUtil;
import org.ymjava.medical.db.AllPackage.biz.NurseQuestionBiz;
import org.ymjava.medical.db.AllPackage.biz.PrepareForUserBiz;
import org.ymjava.medical.db.AllPackage.entity.NurseQuestion;
import org.ymjava.medical.db.AllPackage.entity.PrepareForUser;
import org.ymjava.medical.db.AllPackage.entity.WrongReport;

import java.util.*;

@RestController
@RequestMapping("/wx_answer/type_hall")
public class TypeHallController {

    @Autowired
    NurseQuestionBiz nurseQuestionBiz;

    @Autowired
    PrepareForUserBiz prepareForUserBiz;

    @GetMapping("/query_wrong")
    public Object query_wrong(Integer userId,Integer typeId,Integer classId){

        List<NurseQuestion> list_report = new ArrayList<>();

        if(typeId == 1){
            //查错题
            list_report = nurseQuestionBiz.query_wrong(userId, typeId, classId);
        }

        if(typeId == 2){
            //已完成
            list_report = nurseQuestionBiz.query_completed(userId, typeId, classId);
        }

        if(typeId == 3){
            //未完成
            list_report = nurseQuestionBiz.query_no_completed(userId, typeId, classId);
        }

        if(typeId == 4){
            //单选
            list_report = nurseQuestionBiz.query_type(classId,1);
        }

        if(typeId == 5){
            //多选
            list_report = nurseQuestionBiz.query_type(classId,2);
        }

        if(typeId == 7){
            //判断
            list_report = nurseQuestionBiz.query_type(classId,3);
        }

        if(typeId == 6){
            //图片题
            list_report = nurseQuestionBiz.query_Judge(classId);
        }

        if(typeId == 8){
            //收藏
            list_report = nurseQuestionBiz.query_Favorite(classId,userId);
        }




        Map<String, Object> data = new HashMap<>(1);
        data.put("list_report", list_report);

        return ResponseUtil.ok(data);
    }


    @GetMapping("/update_type")
    public Object update_type(Integer userId, Integer questionId,Integer typeId, Integer position,Integer bankId, Integer classId,Integer wrong){

        List<PrepareForUser> wrong_prepares = prepareForUserBiz.queryWrong(questionId,bankId);

        if(wrong_prepares.size() == 0){
            //添加对错
            PrepareForUser wrong_prepare = new PrepareForUser();
            wrong_prepare.setAddTime(new Date());
            wrong_prepare.setDeleted(0);
            wrong_prepare.setPrepareId(classId);
            wrong_prepare.setType(typeId);
            wrong_prepare.setUserId(userId);
            wrong_prepare.setAddTime(new Date());
            wrong_prepare.setBankId(bankId);
            wrong_prepare.setQuestionId(questionId);
            wrong_prepare.setWrong(wrong);
            prepareForUserBiz.insert(wrong_prepare);
        }else{
            //更新
            PrepareForUser wrong_prepare1 = wrong_prepares.get(0);
            wrong_prepare1.setWrong(wrong);
            prepareForUserBiz.updateById(wrong_prepare1);
        }

        return ResponseUtil.ok();
    }


    @GetMapping("/query_bank")
    public Object query_bank(Integer userId,Integer typeId,Integer classId,Integer bankId){

        List<NurseQuestion> list_report = nurseQuestionBiz.query_bank(classId,bankId);
        Map<String, Object> data = new HashMap<>(1);
        data.put("list_report", list_report);


        return ResponseUtil.ok(data);
    }

}
